package top.infopub.mgr.fia.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.infopub.enums.fia.IncomeBillTypeEnum;
import top.infopub.enums.fia.IncomeSettlementModeEnum;
import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.IncomeBillDao;
import top.infopub.mgr.fia.domain.IncomeBillDomain;
import top.infopub.mgr.fia.service.IncomeBillService;
import top.infopub.mgr.fia.vo.IncomeBillVo;
import top.infopub.mgr.flow.cnst.FlowTemplateEnum;
import top.infopub.model.fia.IncomeBill;
import top.infopub.security.vo.AuthorizationVO;
import top.infopub.util.IdFactory;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class IncomeBillServiceImpl extends GenericServiceImpl<IncomeBill, String> implements
		IncomeBillService {

	@Autowired
	private IncomeBillDao incomeBillDao;
	
	@Override
	public GenericDao<IncomeBill, String> getDao() {
		return incomeBillDao;
	}

    @Override
    public Page<IncomeBillDomain> selectPageByDomainWhere(Page<IncomeBillDomain> page,
														  IncomeBillVo incomeBillVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<IncomeBillDomain>)incomeBillDao.selectByDomainWhere(incomeBillVo);
    }

    @Override
	public IncomeBill setIncBillInfo(String proCode, IncomeSettlementModeEnum ism, IncomeBillTypeEnum ibt, BigDecimal incAmt,
									 BigDecimal actualIncAmt, FlowTemplateEnum fte, String bizSguid, AuthorizationVO vo) {
		IncomeBill incomeBill = new IncomeBill();
		incomeBill.setCodes(IdFactory.getUUIDUpper());
		incomeBill.setProCode(proCode);
		incomeBill.setSettlementMode(ism.getCode());
		incomeBill.setIncomeType(ibt.getCode());
		incomeBill.setActIncomeAmount(incAmt);
		incomeBill.setAddBy(vo.getId());
		incomeBill.setAddTime(new Date());
		incomeBill.setUptBy(vo.getId());
		incomeBill.setUptTime(new Date());
		incomeBill.setStatus("1");
		incomeBill.setActualIncomeAmt(actualIncAmt);
		incomeBill.setBizTableName(fte.getSrcBizTable());
		incomeBill.setBizSguid(bizSguid);
		return incomeBill;
	}
}